package dao;

import domain.Log;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LogDao {
    @Select("<script> select * from log  where 1=1" +
//            "<if test='visitTime != null and visitTime.length() != 0'>" +
//            "  and visitTime like '%${value}%'" +
//            "</if>" +
            "<if test='username != null and username.length() != 0'>" +
            "    and username like #{username}" +
            "</if>" +
            " order by id desc" +
            "</script>")
    List<Log> findAll(@Param("username") String username);

    @Insert("insert into log values(null,#{username},#{method},#{url},#{clientIp},#{status},#{visitTime},#{time})")
    void add(Log log);

    @Select("select * from log where id=#{id}")
    Log findById(int id);
}
